package com.baizhi.service.impl;

import com.baizhi.dao.CmfzLogDao;
import com.baizhi.entity.CmfzLog;
import com.baizhi.service.CmfzLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/4/12 0012.
 */
@Service
public class CmfzLogServiceImpl implements CmfzLogService {
    @Autowired
    private CmfzLogDao cmfzLogDao;

    @Override
    public Map showAll(Integer page, Integer rows, String adminUsername) {
        Map map = new HashMap();

        IPage<CmfzLog> iPage = new Page<>(page, rows);
        QueryWrapper<CmfzLog> wrapper = new QueryWrapper<>();
        if (adminUsername != null && !"".equals(adminUsername)) {
            wrapper.like("admin_username", adminUsername);
        } else {
            wrapper = null;
        }
        IPage<CmfzLog> cmfzAlbumIPage = cmfzLogDao.selectPage(iPage, wrapper);
        List<CmfzLog> records = cmfzAlbumIPage.getRecords();
        long total = cmfzAlbumIPage.getTotal();

        map.put("total", total);
        map.put("rows", records);

        return map;
    }

    @Override
    public Map deleteMany(int[] ids) {
        Map map = new HashMap();

         /*将数组转成List集合*/
        List<Integer> list = new ArrayList<>();
        for (int i : ids) {
            list.add(i);
        }

        try {
            cmfzLogDao.deleteBatchIds(list);
            map.put("flag", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("flag", false);
        }

        return map;
    }
}
